import JSZip from 'jszip'
import { saveAs } from 'file-saver'

export const submitPapersToPlatform = async (papers) => {
    // 创建ZIP压缩包
    const zip = new JSZip()
    const papersFolder = zip.folder('papers')

    papers.forEach(paper => {
        papersFolder.file(`${paper.studentId}.json`, JSON.stringify(paper, null, 2))
    })

    // 生成ZIP文件
    const content = await zip.generateAsync({ type: 'blob' })

    // 这里应该是实际上传到平台的代码
    // 以下是模拟实现
    return new Promise((resolve) => {
        setTimeout(() => {
            // 模拟上传完成后提供下载
            saveAs(content, `exam-papers-${new Date().toISOString().slice(0, 10)}.zip`)
            resolve({
                success: true,
                message: '试卷已成功打包并上传',
                count: papers.length
            })
        }, 1500)
    })
}